package javaclickers.javaclickers.mobile;

import java.util.Timer;
import java.util.TimerTask;

public class Contador implements Runnable {
	private Timer timer = new Timer();
	private SingletonParameters param = SingletonParameters
			.getSingletonParameters();

	public void run() {
		timer.scheduleAtFixedRate(new ActualizarTimer(), 0, 1000);
		timer.schedule(new mainTask(),
				(param.getParametros().getTiempo() * 1000));
	}

	private class mainTask extends TimerTask {
		public void run() {
			param.getParametros().getContestarProblema().enviarSeleccion();
		}
	}

	private class ActualizarTimer extends TimerTask {
		public void run() {
			param.getParametros().getContestarProblema().actualizarTimer();
		}
	}

	public void cancelarTimer() {
		timer.cancel();
		timer = new Timer();
	}

}
